﻿using System;
using System.Collections.Generic;
using System.Collections;
using System.Data;
using System.Globalization;
using System.IO;
using System.Security;
using System.Web;
using Tiffer;

public class Common
{
    // Fields
    public const string LABLE_CONT = "contFile";
    public const string LABLE_FILE = "lblFile";
    public const string LABLE_PAGES = "divPages";
    public const string PAGE_COUNT = "lblPageCount";

    // Methods
    private static DataView FilesDataView(DirectoryInfo di)
    {
        DataView defaultView;
        try
        {
            NumberFormatInfo provider = new NumberFormatInfo();
            provider.NumberDecimalDigits = 0;
            DataTable table = new DataTable();
            table.Columns.Add("name").MaxLength = 0x200;
            table.Columns.Add("size").MaxLength = 50;
            table.Columns.Add("date").MaxLength = 50;
            table.Columns.Add("dateSort").MaxLength = 50;
            table.Columns.Add("pages").MaxLength = 50;
            DataRowCollection rows = table.Rows;
            foreach (FileInfo info2 in di.GetFiles("*.tif"))
            {
                int num = -1;
                try
                {
                    num = Tiff.PageCount(info2.FullName);
                }
                catch (Exception)
                {
                }
                object[] values = new object[] { Path.GetFileNameWithoutExtension(info2.FullName), info2.Length.ToString("N", provider), info2.CreationTime.ToString("g"), info2.CreationTime.ToString("s"), num };
                rows.Add(values);
            }
            table.DefaultView.Sort = "dateSort";
            defaultView = table.DefaultView;
        }
        catch (SecurityException exception)
        {
            throw new Exception("\nCan't access " + di.FullName + ".\n" + exception.Message);
        }
        catch (IOException exception2)
        {
            throw new Exception("\nFile " + di.FullName + " not found.\n" + exception2.Message);
        }
        return defaultView;
    }

    public static string ImageList()
    {
        DirectoryInfo di = new DirectoryInfo(Dimok.Config.imaging.WS.ImagePath);
        ArrayList list = new ArrayList();
        foreach (DataRowView view in FilesDataView(di))
        {
            list.Add(string.Concat(new object[] { "<DIV id=\"contFile\"><DIV nowrap><SPAN id=\"lblFile\" title=\"Size:", view["size"].ToString(), " ; Date:", view["date"], "\">", view["name"].ToString(), "</SPAN>(<SPAN id=\"lblPageCount\">", view["pages"].ToString(), "</SPAN>)</DIV><DIV id=\"divPages\" style=\"display:none\"></DIV></DIV>" }));
        }
        return string.Join("", (string[]) list.ToArray(Type.GetType("System.String")));
    }
}
